import urllib.request


def load_baidu():
    url = "http://www.baidu.com"

    # 创建请求对象
    request = urllib.request.Request(url)
    # 请求网络数据
    response = urllib.request.urlopen(request)
    # 响应头
    # print(response.headers)

    data = response.read().decode("utf-8")

    request_header = request.headers
    # 获取请求头的信息
    print(request_header)
    with open("02header.html", "w", encoding="utf-8") as f:
        f.write(data)




load_baidu()